/*
 * Course:        COMP 380
 * Semester:      Summer 2012
 * Assignment:    Text To Speech
 * File Name:     Email.java
 * Author:        James Paul Pan
 * 				  Kenneth Wakeland
 * 				  Peter Xaymountry
 * Group #:		  Group #3
 */

package com.comp380.texttospeech;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

/*
 * This class purpose is to let the user select which Email
 * application they would like to select from.
 */
public class Email extends Activity implements OnClickListener
{
	//Initialize the button variables.
	Button btnGmail, btnEmail, btnReturn;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		// Keep the screen orientation in portrait mode
    	super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    	
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		// Set the layout for this activity.
		setContentView(R.layout.email);
		
		// Pass the variable to correspond with the Gmail button.
		btnGmail = (Button) findViewById(R.id.buttonGmail);
		
		// When the button is click it goes to the onClick method and take
		// the user to their Gmail screen.
		btnGmail.setOnClickListener(this);
		
		// Pass the variable to correspond with the Email button.
		btnEmail = (Button) findViewById(R.id.buttonEmail);
		
		// When the button is click it goes to the onClick method and take
		// the user to their Email screen.
		btnEmail.setOnClickListener(this);
		
		// Pass the variable to correspond with the Return button.
		btnReturn = (Button) findViewById(R.id.buttonReturn);
		
		// When the button is click it goes to the onClick method and take
		// the user back to the Import screen.
		btnReturn.setOnClickListener(this);
	}
	
	/*
	 * This method will handle what happen when the user click on a particular 
	 * button.
	 */
	public void onClick(View v) 
	{
		if (v.getId() == R.id.buttonGmail)
		{
			try
			{
				// Display a message that the user click on the Gmail button.
				Toast.makeText(getBaseContext(), "Going to your Gmail inbox", Toast.LENGTH_SHORT).show();
				
				
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity");
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				
				// This will start the transition to the user Gmail inbox screen.
				startActivity(intent);
			}
			
			catch(Exception e)
			{
				// Display a message that the user don't have the
				// Gmail app installed on their phone.
				Toast.makeText(getBaseContext(), "You don't have the Gmail app installed", Toast.LENGTH_LONG).show();
			}
			
			
		}
		
		else if(v.getId() == R.id.buttonEmail)
		{	
			try
			{
				// Display a message that the user click on the Email button.
				Toast.makeText(getBaseContext(), "Going to your Email inbox", Toast.LENGTH_SHORT).show();
				
				// This variable will store the function that will take the 
				// user to their Email screen.
				Intent intent = getPackageManager().getLaunchIntentForPackage(
					"com.android.email");
			
				// This will start the transition to the Import screen.
				startActivity(intent);
			}
			
			catch(Exception e)
			{
				// Display a message that the user rooted their phone or using 
				// an HTC phone which is throwing an error.
				Toast.makeText(getBaseContext(), "You rooted your phone or using a HTC phone, so get the gmail app instead", Toast.LENGTH_LONG).show();
			}	
		}
		
		else if(v.getId() == R.id.buttonReturn)
		{
			// Display a message that the user click on the Email button.
			Toast.makeText(getBaseContext(), "Going to the Import screen", Toast.LENGTH_SHORT).show();
			
			// This variable will store the function that will take the 
			// user to the Import screen.
			Intent intent = new Intent(getBaseContext(), importwindow.class);
			
			// This will start the transition to the Import screen.
			startActivity(intent);
		}
	}
}
